from flask import Flask

from datetime import timedelta
import os
from flask_sqlalchemy import SQLAlchemy
from flask_cache import Cache

#缓存
cache = Cache(config={"CACHE_TYPE":"simple"},with_jinja2_ext=False)

#==================    初始化     =================================
app = Flask(__name__)

app.config['PERMANENT_SESSION_LIFETIME']=timedelta(days=7) #session保存时间。
app.config['SECRET_KEY']=os.urandom(24)

#配置数据库
# pip install mysql-connector-python
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:root@localhost:3306/first?charset=utf8mb4"
app.config['SQLALCHEMY_COMMIT_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['CACHE_DEFAULT_TIMEOUT'] = 120
cache.init_app(app)
db = SQLAlchemy(app)
